<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            工序产量查询
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">开始日期</div>
                    <div class="aui-list-item-input" onclick="timePicker('dateStart');">
                        <input type="text" placeholder="选择日期" class="aui-input" id="dateStart">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">结束日期</div>
                    <div class="aui-list-item-input" onclick="timePicker('dateEnd');">
                        <input type="text" placeholder="选择日期" class="aui-input" id="dateEnd">
                    </div>
                </div>
            </li>
            <!-- <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">工序</div>
                    <div class="aui-list-item-input" onclick="goSelectOpCode()">
                        <input id="opCode" placeholder="选择工序" readonly></input>
                    </div>
                </div>
            </li> -->
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="doSearch()">查询</div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr
                        style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center'>日期</td>
                        <td algin='center'>工序</td>
                        <td algin='center'>合格数</td>
                        <td algin='center'>不合格数</td>
                        <td algin='center'>完工总数</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
    </div>

    <!-- <div>
        <div style="height:60px;"></div>
        <footer class="aui-bar aui-bar-tab" id="footer">
            <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
                <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
            </div>
        </footer>
    </div> -->

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var opCode = "";
    var opName = "";
    var opid = "";
    var equipUniqueId = "";   //设备唯一号
    var workCellCode =""; 

    //初始化
    apiready = function () {
        $("#workCenterCode").focus();
        idSelector = "workCenterCode";
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //1:查询产线工序信息
        searchWorkCenterData();
    }

    //查询产线工位信息
    function searchWorkCenterData() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getOpCodeByUniCode";
        var data = {
            values: {
                clientCode: equipUniqueId,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                if (myobj.code == 0) {
                    //标题
                    opCode = myobj.opCode;
                    workCellCode = myobj.workCellCode;
                } else {
                    api.toast({
                        msg: myobj.msg,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function setOpCode(id, code, name) {
        opid = id;
        opCode = code;
        opName = name;
        document.getElementById('opCode').value = code;
    }


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#" + id).val(date);
            }
        });
    }



    // //扫描
    // function doScan() {
    //     var moduleScanner = api.require('moduleScanner');
    //     var params = {
    //         top: 150, //扫描窗口的上边距
    //         width: 250, //扫描窗口的宽
    //         height: 250, //扫描窗口的高
    //         useColor: false, //是否使用自己设定的颜色(startColor和endColor),
    //         //如果不使用设定的颜色就使用默认的那张网格图
    //         startColor: '#0F08C8FF', //渐变起始颜色
    //         endColor: '#7F08C8FF', //渐变结束颜色
    //         animTime: 2200, //扫描动画时间,单位为毫秒
    //     };
    //     moduleScanner.toScannerActivityForResult(params, function (ret, err) {
    //         //alert(ret);扫码的结果都是编码
    //         //1：仓库
    //         if (idSelector == 'workCenterCode') {

    //             $("#workCenterCode").val(ret);
    //             //查询仓库
    //             getWorkCenter(ret, idSelector);

    //             //2:库位
    //         } else if (idSelector == 'workCellCode') {

    //             $("#workCellCode").val(ret);
    //             //查询库位
    //             getWorkCell(ret, idSelector);

    //         }
    //     });
    // }


    //3；PDA自带扫描回车事件
    $("#opCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {
            $("#opCode").val(sm);
            // console.log("扫描回车事件：" + sm);
        }
    });


    function goSelectOpCode() {


        api.openWin({
            name: 'paOpCodeDaq',
            url: 'paOpCodeDaq.html',
            pageParam: {
                name: "uwmPaDaqSelect",
            }
        });

    }



    //查询
    function doSearch() {
        //计划日期起
        var dateStart = $("#dateStart").val();
        //计划日期止
        var dateEnd = $("#dateEnd").val();

        if (opCode == null || opCode == "" || opCode == undefined) {
            api.toast({
                msg: "唯一号【" + equipUniqueId + "】未配置工序信息",
                duration: 3000
            });
            return;
        }

        if (dateStart == null || dateStart == "" || dateStart == undefined) {
            api.toast({
                msg: "请选择开始日期",
                duration: 3000
            });
            return;
        }
        if (dateEnd == null || dateEnd == "" || dateEnd == undefined) {
            api.toast({
                msg: "请选择结束日期",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/doSearchOpDaq";
        var data = {
            values: {
                dateStart: dateStart,
                dateEnd: dateEnd,
                opCode: opCode,
                stationCode: workCellCode,
                un: un
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
                        html += "<td name='padate'>" + list[i].padate + "</td>";
                        html += "<td name='ext07'>" + list[i].ext07 + "</td>";
                        html += "<td name='hgQty'>" + list[i].hgQty + "</td>";
                        html += "<td name='bhgQty'>" + list[i].bhgQty + "</td>";
                        html += "<td name='sumQty'>" + list[i].sumQty + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("连接超时，请耐心等待");
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>